package model

import "gorm.io/gorm"

type Friend struct {
	gorm.Model
	UserId   int    `gorm:"type:int" json:"userId"`
	FriendId int    `gorm:"type:int" json:"friendId"`
	ReMark   string `gorm:"type:varchar(30)" json:"reMark"`
	Reject   string `gorm:"type:varchar(30)" json:"reject"`
	Status   int    `gorm:"type:int;default:0" json:"status"`
}

func (f *Friend) IsFriend(db *gorm.DB, userId int, friendId int) error {
	return db.Where("user_id = ? and friend_id = ?", userId, friendId).First(&f).Error
}

func (f *Friend) AddFriend(db *gorm.DB) error {
	err := db.Create(&f).Error
	return err
}
func (f *Friend) FriendApply(db *gorm.DB, userId int, friendId int, status int) error {
	err := db.Model(&f).Where("user_id = ? and friend_id = ?", userId, friendId).
		Update("status", status).First(&f).Error
	return err
}
